import config from '@/axios'
import qs from 'qs'

function postJson (url, params, isLoading) {
  return new Promise((resolve, reject) => {
    config({
      method: 'POST',
      url,
      data: qs.stringify({ ...params }),
      isLoading: isLoading || false
    })
      .then(res => {
        resolve(res)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

function getJson (url, query, isLoading) {
  return new Promise((resolve, reject) => {
    config({
      methods: 'GET',
      url,
      params: query,
      isLoading: isLoading || false
    })
      .then(res => {
        resolve(res)
      })
      .catch(err => {
        reject(err)
      })
  })
}

export default {
  postJson,
  getJson
}
